CS231n |
您所在的位置:网站首页 › Python报错name is not defined › CS231n |
配置
实验环境:Google Colab 代码存放:Google Drive 环境配置:Python3.10,无GPU 找了很多方法,但是最后莫名奇妙的解决了,不知道为什么,可以评论告诉我。 经历运行代码时(没截图),报错: NameError: name 'col2im_6d_cython' is not defined找了好几种方法: 第一种方法说是col2im_6d_cython加载失败,将im2col_cpython.c和 im2col_cython.cpython-310-x86_64-linux-gnu.so删除,然后重新运行代码块 # Remember to restart the runtime after executing this cell! %cd /content/drive/My\ Drive/$FOLDERNAME/cs231n/ !python setup.py build_ext --inplace %cd /content/drive/My\ Drive/$FOLDERNAME/但是没有任何用,我也看了文件fast_layer.py和im2col_cython_psy文件的引用路径没有问题,且函数也都存在。 第二种方法添加下面代码到代码块中运行 import pyximport pyximport.install()代码是 cs231n ConvolutionNetworks of spring 2023中的(其他问题我不清楚): # Add here two lines # import pyximport # pyximport.install() # Rel errors should be around e-9 or less. from cs231n.fast_layers import conv_forward_fast, conv_backward_fast from time import time np.random.seed(231) x = np.random.randn(100, 3, 31, 31) w = np.random.randn(25, 3, 3, 3) b = np.random.randn(25,) dout = np.random.randn(100, 25, 16, 16) conv_param = {'stride': 2, 'pad': 1} t0 = time() out_naive, cache_naive = conv_forward_naive(x, w, b, conv_param) t1 = time() out_fast, cache_fast = conv_forward_fast(x, w, b, conv_param) t2 = time() ···发现输出没有问题后,把这两行代码删除,再次运行也没有问题。 输出结果: Testing conv_forward_fast: Naive: 0.302786s Fast: 0.013577s Speedup: 22.300660x Difference: 4.926407851494105e-11 Testing conv_backward_fast: Naive: 1.151665s Fast: 0.020583s Speedup: 55.951166x dx difference: 1.006330206620509e-11 dw difference: 1.6835243644808872e-13 db difference: 0.0 题外话在StackOverflow上看到同样的问题,尝试了以前别人的回答,发现的确可行后也进行了解答。 StackOverFlow上的问题解答 别人的解答是在fast_layers.py文件中,前面添加这两行代码,好像也是可行的(没试过,运行成功后也试不了了) import pyximport pyximport.install() # add above two lines before here code import cs231n.im2col_cython |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |